//
//  ConfirmView.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/20.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "ConfirmView.h"
#import "DefaultButton.h"

@implementation ConfirmView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame: frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //分割线
        UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0,0, WIDTH, 1)];
        lineView1.backgroundColor = [UIColor blackColor];
        lineView1.alpha = 0.1;
        [self  addSubview:lineView1];
        
        self.totalPrice = [[UILabel alloc] init];
        _totalPrice.font = [UIFont systemFontOfSize:15];
        _totalPrice.textColor = DEFAULT_COLOR;
        _totalPrice.font = [UIFont boldSystemFontOfSize:15];
        [self addSubview:_totalPrice];
        
        UILabel *Label = [[UILabel alloc] init];
        Label.font = [UIFont systemFontOfSize:13];
        Label.text = @"含运费";
        Label.textColor = [UIColor grayColor];
        [self addSubview:Label];
        
        DefaultButton *button = [[DefaultButton alloc] init];
        [button setTitle:@"确认下单" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(ConfirmOrderDidClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        
        [_totalPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.mas_centerY).offset(-10);
            make.left.equalTo(self.mas_left).offset(15);
            make.height.mas_equalTo(15);
        }];
        
        
        [Label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_totalPrice.mas_bottom).offset(5);
            make.left.equalTo(_totalPrice.mas_left);
        }];
        
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            
            if (iPhone5) {
                make.centerY.equalTo(self.mas_centerY).offset(-5);
            } else {
                make.centerY.equalTo(self.mas_centerY);
            }
            make.right.equalTo(self.mas_right).offset(-15);
            make.height.mas_equalTo(WIDTH/10);
            make.width.mas_equalTo(WIDTH/4);
        }];
        
        
    }
    return self;
}

- (void)ConfirmOrderDidClickButton:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(confirmViewOrderDidClick:)]) {
        [self.delegate confirmViewOrderDidClick:button];
    }
}

@end
